<?php

namespace App\HttpController;

use EasySwoole\Http\AbstractInterface\AbstractRouter;
use EasySwoole\Http\Message\Status;
use FastRoute\RouteCollector;
use EasySwoole\Http\Response;
use EasySwoole\Http\Request;
use EasySwoole\EasySwoole\Logger;

class Router extends AbstractRouter{
    public function initialize(RouteCollector $routeCollector){
        //开启全局模式拦截,局模式拦截下,路由将只匹配Router.php中的控制器方法响应,将不会执行框架的默认解析
        //不开启在拦截的状态下依旧会执行框架的默认解析
        $this->setGlobalMode(true);
//        $this->setMethodNotAllowCallBack(function (Request $request,Response $response){
//            $response->withStatus(Status::CODE_METHOD_NOT_ALLOWED);
//            $response->write('Sorry,the method not allowed.');
//        });
        $this->setRouterNotFoundCallBack(function (Request $request,Response $response){
            $response->withStatus(Status::CODE_NOT_FOUND);
            $response->write('Sorry, the page you are looking for could not be found.');
        });
        Logger::getInstance()->log('路由进来了','router');
//        $this->addAdminRouter($routeCollector);
        $routeCollector->get('/', '/Home/Index');
        $routeCollector->post('/upload', '/Home/Index/upload');
        $routeCollector->post('/login', '/Home/Login');




        //管理后台
        $routeCollector->post('/admin/login', '/Admin/Login');//登陆提交
        $routeCollector->get('/admin/captcha', '/Admin/Login/captcha');//验证码

        $routeCollector->get('/admin/manage', '/Admin/Manage');//管理员列表
        $routeCollector->get('/admin/manage/info', '/Admin/Manage/info');//管理员详情
        $routeCollector->post('/admin/manage/update', '/Admin/Manage/update');//管理员更新
        $routeCollector->get('/admin/manage/destroy', '/Admin/Manage/destroy');//管理员删除

        $routeCollector->get('/admin/role', '/Admin/Role');//角色列表
        $routeCollector->post('/admin/role/update', '/Admin/Role/update');//角色更新
        $routeCollector->get('/admin/role/destroy', '/Admin/Role/destroy');//角色删除
        $routeCollector->get('/admin/role/access', '/Admin/Role/access');//角色权限
        $routeCollector->post('/admin/role/access/update', '/Admin/Role/accessUpdate');//角色权限更新

            //分类管理
            $routeCollector->get('/admin/categorys', '/Admin/Category');//分类管理列表
            $routeCollector->post('/admin/categorys/update', '/Admin/Category/update');//更新分类管理信息
            $routeCollector->delete('/admin/categorys/delete', '/Admin/Category/destroy');//删除分类管理信息
    }
}
